﻿using System;
using System.Text;

enum Universities { SofiaUniversity, UNWE, TechnicalUniversitySofia };
enum Faculties { FMI, LF, CF, PF,FF };
enum Specialties { CS, SE, IS };

class Student :ICloneable,IComparable<Student>
{
    public string FirstName { get; set; }
    public string SecondName { get; set; }
    public string LastName { get; set; }
    public string SSN { get; private set; }
    public string PermanentAdress { get; set; }
    public string Phone { get; set; }
    public int Course { get; set; }
    public Faculties Faculty { get; set; }
    public Universities University { get; set; }
    public Specialties Specialty { get; set; }
    
    public override bool Equals(object obj)
    {
        Student other = obj as Student;
        if (other == null)
        {
            return false;
        }
        if (other.SSN != this.SSN)
        {
            return false;
        }
        return true;
    }

    public Student(string SSN)
    {
        this.SSN = SSN;
    }

    public override string ToString()
    {
        StringBuilder resultBuilder = new StringBuilder();
        resultBuilder.AppendFormat("Student: {0} {1} {2}\n",FirstName,SecondName,LastName);
        resultBuilder.AppendFormat("University: {0}, Faculty: {1}, Speciality: {2}, Course: {3}\n", University, Faculty, Specialty, Course);
        resultBuilder.AppendFormat("Adress: {0}\n", PermanentAdress);
        resultBuilder.AppendFormat("Phone: {0}\n", Phone);
        string result = resultBuilder.ToString();
        return result;
    }

    public static bool operator ==(Student first, Student second)
    {
        return first.Equals(second);
    }

    public static bool operator !=(Student first, Student second)
    {
        return !first.Equals(second);
    }

    public override int GetHashCode()
    {
        return SSN.GetHashCode() ^ (PermanentAdress.GetHashCode() & LastName.GetHashCode());
    }

    public object Clone()
    {
        Student resultingClone = new Student(this.SSN);
        resultingClone.FirstName = (string)this.FirstName.Clone();
        resultingClone.SecondName = (string)this.SecondName.Clone();
        resultingClone.LastName = (string)this.LastName.Clone();
        resultingClone.PermanentAdress = (string)this.PermanentAdress.Clone();
        resultingClone.Phone = (string)this.Phone.Clone();
        resultingClone.Course = this.Course;
        resultingClone.Faculty = this.Faculty;
        resultingClone.University = this.University;
        resultingClone.Specialty = this.Specialty;
        return resultingClone;
    }

    public int CompareTo(Student other)
    {
        if (this.FirstName == other.FirstName)
        {
            if (this.SecondName == other.SecondName)
            {
                if (this.LastName == other.LastName)
                {
                    return other.SSN.CompareTo(this.SSN);
                }
                return this.LastName.CompareTo(other.LastName);
            }
            return this.SecondName.CompareTo(other.SecondName);
        }
        return this.FirstName.CompareTo(other.FirstName);
    }

    public static void Main()
    {
        Student testStudent = new Student("1234");
        testStudent.FirstName = "Ivan";
        testStudent.SecondName = "Petkov";
        testStudent.LastName = "Vasilev";
        testStudent.PermanentAdress = "somewhere";
        testStudent.Phone = "0123456789";
        testStudent.Faculty = Faculties.FMI;
        testStudent.University = Universities.SofiaUniversity;
        testStudent.Specialty = Specialties.CS;
        testStudent.Course = 13;
        Console.WriteLine(testStudent);

        Student testStudent2 = new Student("12345");
        testStudent2.FirstName = "Ivan";
        testStudent2.SecondName = "Petkov";
        testStudent2.LastName = "Vasilev";
        testStudent2.PermanentAdress = "somewhere";
        testStudent2.Phone = "0123456789";
        testStudent2.Faculty = Faculties.FMI;
        testStudent2.University = Universities.SofiaUniversity;
        testStudent2.Specialty = Specialties.CS;
        testStudent2.Course = 13;
        Console.WriteLine(testStudent);

        Student clone = (Student)testStudent.Clone();
        clone.University = Universities.TechnicalUniversitySofia;
        clone.SecondName = "Qetkov";

        Console.WriteLine("Cloned and changed:\n {0}",clone);
        Console.WriteLine("Old: \n{0}",testStudent);

        Console.WriteLine(testStudent2.CompareTo(testStudent));
    }
}
